public class Teacher implements Comparable<Teacher> {
    private int id;
    private String name;
    private int age;

    public Teacher(int id, String name, int age) {
        this.id = id;
        this.name = name;
        this.age = age;
    }

    // Getters
    public int getId() {
        return id;
    }

    public String getName() {
        return name;
    }

    public int getAge() {
        return age;
    }

    @Override
    public String toString() {
        return "Teacher{id=" + id + ", name='" + name + "', age=" + age + "}";
    }

    // 实现Comparable接口的compareTo方法
    @Override
    public int compareTo(Teacher other) {
        // 先按名字排序
        int nameCompare = this.name.compareTo(other.name);
        if (nameCompare != 0) {
            return nameCompare;
        }

        // 名字相同则按年龄排序
        int ageCompare = Integer.compare(this.age, other.age);
        if (ageCompare != 0) {
            return ageCompare;
        }

        // 年龄相同则按id排序
        return Integer.compare(this.id, other.id);
    }
}
